﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VMC.Domain.Model.Service.Abstract;
using VMC.Domain.Model.Common;
using System.Reflection;

namespace VMC.Domain.Model.Service
{
    public class ModelService : IModelService
    {
        public virtual void Dispose() { }
        public virtual Dictionary<string, string> GetErrors() { return new Dictionary<string, string>(); }
        public IEnumerable<SelectListItem> GetSelectList<T>(IEnumerable<T> SourceList, string TextProperty, string ValueProperty, string SelectedValue = "") where T : class
        {

            List<SelectListItem> SelectList = new List<SelectListItem>();
            if (SourceList != null)
            {
                foreach (T TObject in SourceList)
                {
                    SelectListItem mTemp = new SelectListItem();
                    //mTemp.Text = TObject.AreaName;
                    mTemp.Text = TObject.GetType().GetProperty(TextProperty).GetValue(TObject, null).ToString();
                    mTemp.Selected = false;
                    mTemp.Value = TObject.GetType().GetProperty(ValueProperty).GetValue(TObject, null).ToString();
                    if (SelectedValue == mTemp.Value) mTemp.Selected = true;
                    SelectList.Add(mTemp);
                }
            }
            return SelectList.ToList();
        }
    }
}
